import React, { lazy } from 'react';
import {createBrowserRouter} from 'react-router-dom';
import type { RouteObject } from 'react-router-dom';
import {
    CopyOutlined,
    CalendarOutlined,
    WarningOutlined,
    FileAddOutlined,
    ScheduleOutlined
} from '@ant-design/icons'

const Login = lazy(() => import('../views/Login/Login'))
const Home = lazy(() => import('../views/Home/Home'))
const Message = lazy(() => import('../views/Message/Message'))
const My = lazy(() => import('../views/My/My'))
const BeforeEach = lazy(() => import('../components/BeforeEach/BeforeEach'))

declare module 'react-router' {
    interface IndexRouteObject {
        meta?: {
            menu?: boolean
            title: string
            icon?: React.ReactNode
            auth?: boolean
        }
    }
    interface NonIndexRouteObject {
        meta?: {
            menu?: boolean
            title: string
            icon?: React.ReactNode
            auth?: boolean
        }
    }
}

export const routes:RouteObject[] = [
    {
        path: '/',
        element: React.createElement(Login),
    },
    {
        path: '/login',
        element: React.createElement(BeforeEach, null, React.createElement(Login)),
    },
    {
        path: '/home',
        element: React.createElement(BeforeEach, null, React.createElement(Home)),
        meta: {
            menu:true,
            title: '一个系统',
            icon: React.createElement(CopyOutlined),
            auth: true
        },
        children: [
            {
                path: 'message',
                element: React.createElement(Message),
                meta: {
                    menu:true,
                    title: '信息',
                    icon: React.createElement(CopyOutlined),
                    auth: true
                }
            },
            {
                path: 'my',
                element: React.createElement(My),
                meta: {
                    menu:true,
                    title: '我的',
                    icon: React.createElement(CopyOutlined),
                    auth: true
                }
            }
        ]
    }
];

const router = createBrowserRouter(routes)

export default router